<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" encoding="windows-1250" indent="yes"/> 

  <xsl:param name="lang">cs</xsl:param>
  
  <xsl:template match="@*">
    <xsl:copy/> 
  </xsl:template>

  <xsl:template match="/">
    <CViews>
      <xsl:apply-templates select="/CViews/CView"/>
    </CViews>
  </xsl:template>
 
  <xsl:template match="CView">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <Code ro="0" ext=""/>
      <Code ro="1" ext="_ro"/>
      <xsl:apply-templates select="CVTitles"/>
      <xsl:apply-templates select="CVInclude"/>
    </xsl:copy>
  </xsl:template>

 <xsl:template match="CVInclude">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:call-template name="getPages"/>
     <xsl:call-template name="getPages">
       <xsl:with-param name="readonly">1</xsl:with-param>
     </xsl:call-template>
     <xsl:copy-of select="Concept"/>
     <xsl:copy-of select="Keys"/>
     <xsl:apply-templates select="CVITitles"/>
     <xsl:apply-templates select="CVIProperties"/>
     <xsl:call-template name="getSchedules"/>
     <xsl:apply-templates select="CVIRels"/>
     <xsl:copy-of select="CVIStyles"/>     
     <xsl:copy-of select="CVICGroups"/>
     <xsl:copy-of select="ConsistencyChecks"/>     
   </xsl:copy>
 </xsl:template>

 <xsl:template match="CVIRels">
   <xsl:copy>
     <xsl:apply-templates select="CVIRel"/>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="CVIRel">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:copy-of select="CVIRBindings"/>
     <xsl:apply-templates select="CVInclude"/>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="CVIProperties">
   <xsl:copy>
     <xsl:apply-templates select="CVIProperty">
       <xsl:sort select="@position" data-type="number" order="ascending"/>
     </xsl:apply-templates>
   </xsl:copy>
 </xsl:template>


 <xsl:template match="CVIProperty">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:if test="@key='1'">
       <xsl:attribute name="attr">1</xsl:attribute>
       <xsl:attribute name="mandat">1</xsl:attribute>
       <xsl:attribute name="len">36</xsl:attribute>
       <xsl:attribute name="type">char</xsl:attribute>
     </xsl:if>
     <xsl:if test="(not(@len) or @len='') and @key='0'">
       <xsl:attribute name="len">12</xsl:attribute>
     </xsl:if>
     <xsl:variable name="lowname">
       <xsl:call-template name="toLowerCase"><xsl:with-param name="prm"><xsl:value-of select="@name"/></xsl:with-param></xsl:call-template>
     </xsl:variable>
     <xsl:attribute name="lowname"><xsl:value-of select="$lowname"/></xsl:attribute>
     <xsl:variable name="nickname">
       <xsl:choose>
         <xsl:when test="substring-before(@name,'/')='..'">
           <xsl:value-of select="translate(substring-after(@name,'/'),'/','.')"/>
         </xsl:when>
         <xsl:otherwise>
           <xsl:value-of select="translate(@name,'/','.')"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:variable>
     <xsl:attribute name="nickname"><xsl:value-of select="$nickname"/></xsl:attribute>
     <xsl:attribute name="nicknamelow">
       <xsl:call-template name="toLowerCase"><xsl:with-param name="prm"><xsl:value-of select="$nickname"/></xsl:with-param></xsl:call-template>
     </xsl:attribute>
     <xsl:attribute name="rootnickpath"><xsl:value-of select="../../@rootnickpath"/>/<xsl:value-of select="@name"/></xsl:attribute>
     
     <xsl:choose>
       <xsl:when test="self::node()[not(contains(@name,'/'))]">
         <xsl:copy-of select="PropGroup"/>       
       </xsl:when>
       <xsl:otherwise>
         <xsl:attribute name="formcode">
           <xsl:call-template name="toLowerCase"><xsl:with-param name="prm"><xsl:value-of select="translate(@path,'/_','yx')"/><xsl:value-of select="translate(@simplenamelow,'_','x')"/></xsl:with-param></xsl:call-template>
         </xsl:attribute>
         <PropGroup>
           <xsl:apply-templates select="PropGroup/@*"/>
           <xsl:attribute name="create"><xsl:value-of select="number(count(../CVIProperty[@path=current()/@path and @oncreate='show'])>0)"/></xsl:attribute>
           <xsl:attribute name="detail"><xsl:value-of select="number(count(../CVIProperty[@path=current()/@path and @ondetail='show'])>0)"/></xsl:attribute>
           <xsl:attribute name="update"><xsl:value-of select="number(count(../CVIProperty[@path=current()/@path and @onedit='show'])>0)"/></xsl:attribute>
           <xsl:attribute name="select"><xsl:value-of select="number(count(../CVIProperty[@path=current()/@path and @onlist='show'])>0)"/></xsl:attribute>
           <xsl:attribute name="delete"><xsl:value-of select="number(count(../CVIProperty[@path=current()/@path and @ondetail='show'])>0)"/></xsl:attribute>
         </PropGroup>
       </xsl:otherwise>
     </xsl:choose>
     
     <xsl:apply-templates select="RefProp">       
       <xsl:with-param name="inickname"><xsl:value-of select="$nickname"/></xsl:with-param>
     </xsl:apply-templates>
     <xsl:copy-of select="DefaultFilter"/>
     <xsl:apply-templates select="CVIPTitles"/>       
     <xsl:apply-templates select="CPStaticValues"/>
   </xsl:copy>
 </xsl:template>


 <xsl:template match="RefProp">
   <xsl:param name="inickname"></xsl:param>
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     
     <xsl:variable name="nickname"><xsl:value-of select="$inickname"/>.<xsl:value-of select="@refconcept"/>.<xsl:value-of select="@code"/></xsl:variable>
     <xsl:attribute name="nickname"><xsl:value-of select="$nickname"/></xsl:attribute>
     <xsl:attribute name="nicknamelow">
       <xsl:call-template name="toLowerCase"><xsl:with-param name="prm"><xsl:value-of select="$nickname"/></xsl:with-param></xsl:call-template>
     </xsl:attribute>

     <xsl:variable name="t" select="../CVIPTitles/CVIPTitle[@id_lang=$lang]"/>
     <xsl:variable name="tref" select="CVIPTitles/CVIPTitle[@id_lang=$lang]"/>
     <xsl:choose>
       <xsl:when test="not($tref) and not($t)">
         <Title><xsl:value-of select="../@simplename"/></Title>
       </xsl:when>
       <xsl:when test="not($tref)">
         <Title><xsl:value-of select="$t/Title"/></Title>
         <Descr><xsl:value-of select="$t/Descr"/></Descr>
       </xsl:when>
       <xsl:otherwise>
         <Title><xsl:value-of select="$tref/Title"/></Title>
         <Descr><xsl:value-of select="$tref/Descr"/></Descr>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:copy>
 </xsl:template>


 <xsl:template match="CVIPTitles">
   <xsl:variable name="t" select="CVIPTitle[@id_lang=$lang]"/>
   <xsl:choose>
     <xsl:when test="$t">
       <Title><xsl:value-of select="$t/Title"/></Title>
       <Descr><xsl:value-of select="$t/Descr"/></Descr>
     </xsl:when>
     <xsl:otherwise>
       <Title><xsl:value-of select="../@simplename"/></Title>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>


 <xsl:template match="CVITitles">
   <xsl:copy>
     <xsl:apply-templates select="CVITitle[@id_lang=$lang]"/>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="CVITitle">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:copy-of select="Title"/>       
     <xsl:copy-of select="Descr"/>       
   </xsl:copy>
 </xsl:template>
 
 <xsl:template match="CVTitles">
   <xsl:copy>
     <xsl:apply-templates select="CVTitle[@id_lang=$lang]"/>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="CVTitle">
   <xsl:copy>
     <xsl:apply-templates select="@*"/>
     <xsl:copy-of select="Title"/>       
     <xsl:copy-of select="Descr"/>       
   </xsl:copy>
 </xsl:template>
 

  <xsl:template name="getSchedules">
    <Schedules>
      <InsertSchedule>
        <xsl:call-template name="getSchedule">
          <xsl:with-param name="type">insert</xsl:with-param>
          <xsl:with-param name="cvi" select="."/>
        </xsl:call-template>    
      </InsertSchedule>
      <UpdateSchedule>
        <xsl:call-template name="getSchedule">
          <xsl:with-param name="type">update</xsl:with-param>
          <xsl:with-param name="cvi" select="."/>
        </xsl:call-template>    
      </UpdateSchedule>
      <DeleteVirtualSchedule>
        <xsl:call-template name="getSchedule">
          <xsl:with-param name="type">delete</xsl:with-param>
          <xsl:with-param name="cvi" select="."/>
        </xsl:call-template>    
      </DeleteVirtualSchedule>
    </Schedules>
  </xsl:template>  



  <xsl:template name="getSchedule">
    <xsl:param name="type">insert</xsl:param>
    <xsl:param name="cvi"/>
    <xsl:param name="reltype">none</xsl:param>
    <xsl:param name="base">1</xsl:param>
 
    <xsl:variable name="count_ext">
      <xsl:choose>
        <xsl:when test="$type='insert'">
          <xsl:value-of select="count($cvi/ExtConcepts/ExtConcept[@insert='1'])"/>
        </xsl:when>
        <xsl:when test="$type='update'">
          <xsl:value-of select="count($cvi/ExtConcepts/ExtConcept[@update='1'])"/>
        </xsl:when>
        <xsl:when test="$type='delete'">
          <xsl:value-of select="count($cvi/ExtConcepts/ExtConcept[@delete='1'])"/>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    
    <xsl:for-each select="$cvi/CVIRels/CVIRel[@cardinality='1:1']">
    <!-- begin -->
      <xsl:variable name="flag">
      <xsl:for-each select="CVIRBindings/CVIRBinding">

      <xsl:if test="../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='0']">        
        <xsl:value-of select="'false'"/>        
      </xsl:if>

      </xsl:for-each>
      </xsl:variable>
      
      <xsl:if test="$flag!='false'">
        <xsl:call-template name="getSchedule">
          <xsl:with-param name="type"><xsl:value-of select="$type"/></xsl:with-param>
          <xsl:with-param name="cvi" select="CVInclude"/>
          <xsl:with-param name="reltype">1:1</xsl:with-param>
          <xsl:with-param name="base">0</xsl:with-param>          
        </xsl:call-template>          
      </xsl:if>
    </xsl:for-each>
 
   
    <SchedItem base="{$base}" path="{$cvi/@nickname}" concept="{$cvi/@concept}" nickname="{$cvi/@nickname}" reltype="{$reltype}" rootnickpath="{$cvi/@rootnickpath}">
      <xsl:choose>
        <xsl:when test="$cvi/../@cardinality='1:1' or $cvi/../@cardinality='n:1'">
            <KeysIn>

              <xsl:for-each select="$cvi/../CVIRBindings/CVIRBinding">
                <xsl:if test="boolean(../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='0']) or boolean(../../../../CVIProperties/CVIProperty[@simplenamelow=current()/@p1low and @key='0'])">
                  <!--<Key parentprop="{@p1}" param="XX{@p1}{../../CVInclude/@id_cvinclude}" attr="1"/>-->
                  <Key parentprop="{@p2}" childprop="{@p2}" param="XX{@p2}{../../../../@id_cvinclude}" attr="1"/>
                </xsl:if>
              </xsl:for-each>
              <xsl:for-each select="$cvi/CVIRels/CVIRel[@cardinality='1:n']/CVIRBindings/CVIRBinding">
                <xsl:if test="not(preceding::CVIRBinding[../../../../@id_cvinclude=$cvi/@id_cvinclude and @p1=current()/@p1])">
                  <xsl:if test="boolean(../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='0']) or boolean(../../../../CVIProperties/CVIProperty[@simplenamelow=current()/@p1low and @key='0'])">
                    <Key parentprop="{@p1}" childprop="{@p2}" param="XX{@p1}{../../../../@id_cvinclude}" attr="1"/>
                  </xsl:if>
                </xsl:if>
              </xsl:for-each>
            </KeysIn>
          <xsl:if test="$cvi/../CVIRBindings or count($cvi/CVIRels/CVIRel[@cardinality='1:n'])>0">
            <KeysOut>
              <xsl:for-each select="$cvi/../CVIRBindings/CVIRBinding">
                <xsl:if test="../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='1']">
                  <!--<Key parentprop="{@p1}" param="XX{@p1}{../../CVInclude/@id_cvinclude}" attr="1"/>-->
                  <Key parentprop="{@p2}" param="XX{@p2}{../../../../@id_cvinclude}" attr="1"/>
                </xsl:if>
              </xsl:for-each>
              <xsl:for-each select="$cvi/CVIRels/CVIRel[@cardinality='1:n']/CVIRBindings/CVIRBinding">
                <xsl:if test="not(preceding::CVIRBinding[../../../../@id_cvinclude=$cvi/@id_cvinclude and @p1=current()/@p1])">
                  <xsl:if test="../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='1']">
                    <Key parentprop="{@p1}" param="XX{@p1}{../../../../@id_cvinclude}" attr="1"/>
                  </xsl:if>
                </xsl:if>
              </xsl:for-each>
            </KeysOut>
          </xsl:if>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="$cvi/../CVIRBindings[$reltype!='none'] or count($cvi/CVIRels/CVIRel[@cardinality!='1:n'])>0">
            <KeysIn>
              <xsl:for-each select="$cvi/../CVIRBindings/CVIRBinding[$reltype!='none']">
                <xsl:if test="../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='1']">
                  <Key parentprop="{@p1}" childprop="{@p2}" param="XX{@p2}{../../../../@id_cvinclude}" attr="1"/>
                </xsl:if>
              </xsl:for-each>              
              <xsl:for-each select="$cvi/CVIRels/CVIRel[@cardinality!='1:n' and CVInclude/@virtual='0']/CVIRBindings/CVIRBinding">
                <xsl:if test="not(preceding::CVIRBinding[../../../../@id_cvinclude=$cvi/@id_cvinclude and @p2=current()/@p2])">
                  <xsl:if test="../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='1']">
                    <!--<Key parentprop="{@p1}" childprop="{@p2}" param="XX{@p2}{../../CVInclude/@id_cvinclude}" attr="1"/>-->
                    <Key parentprop="{@p2}" childprop="{@p1}" param="XX{@p2}{../../../../@id_cvinclude}" attr="1"/>
                  </xsl:if>
                </xsl:if>
              </xsl:for-each>
            </KeysIn>
          </xsl:if>
          <xsl:if test="count($cvi/CVIRels/CVIRel[@cardinality='1:n'])>0 and number($count_ext)>0">
            <KeysOut>
              <xsl:for-each select="$cvi/CVIRels/CVIRel[@cardinality='1:n']/CVIRBindings/CVIRBinding">
                <xsl:if test="../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='1']">                 <xsl:if test="not(preceding::CVIRBinding[../../../../@id_cvinclude=$cvi/@id_cvinclude and @p1=current()/@p1])">
                    <Key parentprop="{@p1}" param="XX{@p1}{../../../../@id_cvinclude}" attr="1"/>
                  </xsl:if>
                </xsl:if>
              </xsl:for-each>
            </KeysOut>
          </xsl:if>
            <KeysOut>
              <xsl:for-each select="$cvi/CVIRels/CVIRel[@cardinality='1:1' or @cardinality='1:n']/CVIRBindings/CVIRBinding">                
                <xsl:if test="not(preceding::CVIRBinding[../../../../@id_cvinclude=$cvi/@id_cvinclude and @p1=current()/@p1])">
                  <xsl:if test="boolean(../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='0']) or boolean(../../../../CVIProperties/CVIProperty[@simplenamelow=current()/@p1low and @key='0'])">
                    <Key parentprop="{@p1}" param="XX{@p1}{../../../../@id_cvinclude}" attr="1"/>
                  </xsl:if>
                </xsl:if>              
              </xsl:for-each>
            </KeysOut>
        </xsl:otherwise>
      </xsl:choose>
    </SchedItem>

    <xsl:for-each select="$cvi/CVIRels/CVIRel[@cardinality='1:1']">
      <xsl:variable name="flag">
      <xsl:for-each select="CVIRBindings/CVIRBinding">
      
      <xsl:if test="../../CVInclude/CVIProperties/CVIProperty[@simplenamelow=current()/@p2low and @key='0']">        
        <xsl:value-of select="'true'"/>        
      </xsl:if>
      
      </xsl:for-each>
      </xsl:variable>
      
      <xsl:if test="$flag='true'">
        <xsl:call-template name="getSchedule">
          <xsl:with-param name="type"><xsl:value-of select="$type"/></xsl:with-param>
          <xsl:with-param name="cvi" select="CVInclude"/>
          <xsl:with-param name="reltype">1:1</xsl:with-param>
          <xsl:with-param name="base">0</xsl:with-param>          
        </xsl:call-template>          
      </xsl:if>
    </xsl:for-each>
<!-- end -->

    <xsl:choose>
      <xsl:when test="$type='insert'">
        <xsl:call-template name="getScheduleExtConcepts">
          <xsl:with-param name="type"><xsl:value-of select="$type"/></xsl:with-param>
          <xsl:with-param name="cvi" select="$cvi"/>
          <xsl:with-param name="extconcepts" select="$cvi/ExtConcepts/ExtConcept[@insert='1']"/>
        </xsl:call-template>    
      </xsl:when>
      <xsl:when test="$type='update'">
        <xsl:call-template name="getScheduleExtConcepts">
          <xsl:with-param name="type"><xsl:value-of select="$type"/></xsl:with-param>
          <xsl:with-param name="cvi" select="$cvi"/>
          <xsl:with-param name="extconcepts" select="$cvi/ExtConcepts/ExtConcept[@update='1']"/>
        </xsl:call-template>    
      </xsl:when>
    </xsl:choose>
    
  </xsl:template>  


  <xsl:template name="getScheduleExtConcepts">
    <xsl:param name="type">insert</xsl:param>
    <xsl:param name="cvi"/>
    <xsl:param name="extconcepts"/>

    <xsl:for-each select="$extconcepts[not(@defaulttype)]">
      <!-- there is CVInclude for these -->
      <xsl:variable name="cvipath"><xsl:value-of select="../../@rootnickpath"/>/<xsl:value-of select="@path"/></xsl:variable>
      <xsl:variable name="extcvi" select="../../CVIRels/CVIRel/.//CVInclude[@rootnickpath=$cvipath]"/>

      <xsl:choose>
        <xsl:when test="$extcvi">
          <xsl:call-template name="getSchedule">
            <xsl:with-param name="type"><xsl:value-of select="$type"/></xsl:with-param>
            <xsl:with-param name="cvi" select="$extcvi"/>
            <xsl:with-param name="reltype">1:n</xsl:with-param>
            <xsl:with-param name="base">0</xsl:with-param>
          </xsl:call-template>    
        </xsl:when>
        <xsl:otherwise>
          <!-- here we allow a second choice where the property path may contain concept name instead of the include's nickname -->
          <xsl:variable name="extcvi2" select="../../CVIRels/CVIRel/.//CVInclude[@rootpath=$cvipath]"/>
          <xsl:if test="$extcvi2">
            <xsl:call-template name="getSchedule">
              <xsl:with-param name="type"><xsl:value-of select="$type"/></xsl:with-param>
              <xsl:with-param name="cvi" select="$extcvi2"/>
              <xsl:with-param name="reltype">1:n</xsl:with-param>
              <xsl:with-param name="base">0</xsl:with-param>
            </xsl:call-template>    
          </xsl:if>
          <xsl:if test="not($extcvi)">
            <BadCVI cvipath="{$cvipath}" concept="{@concept}"/>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>

    </xsl:for-each>

    <xsl:for-each select="$extconcepts[@defaulttype]">
      <!-- there is no CVInclude for these... -->
      <SchedItem base="0" path="{@concept}" concept="{@concept}" nickname="{@concept}" reltype="1:n" defaulttype="{@defaulttype}">
        <xsl:if test="count(Binding)>0">
          <KeysIn>
            <xsl:for-each select="Binding">
              <Key parentprop="{@p1}" childprop="{@p2}" param="XX{@p2}{../../../@id_cvinclude}" attr="1"/>
            </xsl:for-each>
          </KeysIn>
        </xsl:if>
      </SchedItem>
    </xsl:for-each>
  </xsl:template>  


  <xsl:template name="toLowerCase">
    <xsl:param name="prm"/>
    <xsl:value-of select="translate($prm,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
  </xsl:template>  


  <xsl:template name="getPages">
    <xsl:param name="readonly">0</xsl:param>    
    <xsl:variable name="ext">
      <xsl:if test="$readonly='1'">_ro</xsl:if>
    </xsl:variable>

    <xsl:if test="name(..)='CView'">
      <Page name="nokeysxml" type="nokeysxml" style="gennokeysxml.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
      <xsl:if test="@allowxml='1'">
        <Page name="edtxml" type="edtxml" style="genedtxml.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
        <Page name="crtxml" type="crtxml" style="gencrtxml.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
      </xsl:if>
      <Page name="diff" type="diff" style="gendiff.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
    </xsl:if>

    <xsl:call-template name="getPagesPerType">
      <xsl:with-param name="type">list</xsl:with-param>
      <xsl:with-param name="readonly"><xsl:value-of select="$readonly"/></xsl:with-param>
    </xsl:call-template>     
    
    <xsl:if test="@update='1' or @detail='1'">
      <xsl:call-template name="getPagesPerType">
        <xsl:with-param name="type">form</xsl:with-param>
        <xsl:with-param name="readonly"><xsl:value-of select="$readonly"/></xsl:with-param>
      </xsl:call-template>     
    </xsl:if>
    <xsl:if test="@delete='1' and $readonly='0'">
      <xsl:call-template name="getPagesPerType"><xsl:with-param name="type">delete</xsl:with-param></xsl:call-template>     
    </xsl:if>
    <xsl:if test="$readonly='0'">
      <xsl:if test="@canprint='1'">
        <xsl:call-template name="getPagesPerType"><xsl:with-param name="type">print</xsl:with-param></xsl:call-template>     
      </xsl:if>
    </xsl:if>
    <xsl:if test="@create='1' and $readonly='0'">
      <xsl:call-template name="getPagesPerType"><xsl:with-param name="type">create</xsl:with-param></xsl:call-template>     
      <Page name="flapc{@id_cvinclude}" type="flapc" style="genflapc.xsl" alt="1" ext="" ro="0"/>
      <Page name="insertfailed{@id_cvinclude}" type="insertfailed" style="geninsertfailed.xsl" alt="1" ext="" ro="0"/>
    </xsl:if>
    <xsl:if test="@canexport='1'">
      <Page name="expxls{@id_cvinclude}" type="expxls" style="genexpxls.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
    </xsl:if>
    <Page name="flap{@id_cvinclude}" type="flap" style="genflap.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
    <xsl:if test="@update='1' or @detail='1' or @delete='1'">
      <Page name="flape{@id_cvinclude}" type="flape" style="genflape.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
    </xsl:if>
  </xsl:template>  

  <xsl:template name="getPagesPerType">
    <xsl:param name="type"/>   
    <xsl:param name="readonly">0</xsl:param>
    <xsl:variable name="ext">
      <xsl:if test="$readonly='1'">_ro</xsl:if>
    </xsl:variable>
    <xsl:variable name="id_cvinclude" select="@id_cvinclude"/>
    <xsl:choose>
      <xsl:when test="count(CVIStyles/CVIStyle/Style[StyleType/@name=$type])&gt;0">
        <xsl:for-each select="CVIStyles/CVIStyle/Style[StyleType/@name=$type]">
          <Page type="{$type}" style="{@location}" alt="{position()}" ext="{$ext}" ro="{$readonly}">
            <xsl:attribute name="name">
              <xsl:value-of select="$type"/>
              <xsl:if test="position()&gt;1"><xsl:value-of select="position()"/>alt</xsl:if>
              <xsl:value-of select="$id_cvinclude"/>
            </xsl:attribute>
          </Page>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>  
        <Page name="{$type}{@id_cvinclude}" type="{$type}" style="gen{$type}.xsl" alt="1" ext="{$ext}" ro="{$readonly}"/>
      </xsl:otherwise>  
    </xsl:choose>
  </xsl:template>  

  <xsl:template match="CPStaticValues">
    <CPStaticValues>
      <xsl:apply-templates select="CPStaticValue"/>
    </CPStaticValues>
  </xsl:template>  

  <xsl:template match="CPStaticValue">
    <CPStaticValue>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="statval"/>
      <title>
        <xsl:choose>
          <xsl:when test="CPSTitles/CPSTitle[@id_lang=$lang]"><xsl:value-of select="CPSTitles/CPSTitle[@id_lang=$lang]/Title"/></xsl:when>
          <xsl:otherwise><xsl:value-of select="statval"/></xsl:otherwise>
        </xsl:choose>
      </title>
    </CPStaticValue>
  </xsl:template>  

</xsl:stylesheet>
       
 
